<include file="Public/min-header" />
<link href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/plugins/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<style type="text/css">
	.sorting{text-align: center;}
</style>
<div class="wrapper">
    <include file="Public/breadcrumb"/>
	<section class="content">
       <div class="row">
       		<div class="col-xs-12">
	       		<div class="box">
	             <div class="box-header">
	             <div class="row">
  					<div class="col-md-10">
  						<form action="" method="get">  	  					
		  					<div class="col-xs-3">         
			                    <div class="input-group margin">
			                      <div class="input-group-addon">
			                       		选择时间  <i class="fa fa-calendar"></i>
			                      </div>
			                      <input type="text" style="width:260px;" sty class="form-control pull-right" name="timegap" value="{$timegap}" id="start_time">
			                    </div>
	  						</div>	
	  						<div class="col-xs-3">         
			                    <div class="input-group margin">
			                      <div class="input-group-addon">
			                       		商品名称  
			                      </div>
			                      <input type="text" class="form-control pull-right" id="goods_name" name="goods_name" value="{:I('goods_name')}">
			                    </div>
	  						</div>
	  						<div class="col-xs-3">         
			                    <div class="input-group margin">
			                      <select class="input-sm" name="store_class_cat1" id="store_class_cat1" onchange="get_category2(this.value,'store_class_cat2','0','1');">
			                          <option value="0">请选择一级分类</option>
			                          <volist  name='store_class_cat1' id='vo'>
			                            <option <if condition="$vo.cat_id  eq I('store_class_cat1')">selected</if> value="{$vo.cat_id}">{$vo.cat_name}</option>
			                          </volist >
			                      </select>
			                      <select class="input-sm" name="store_class_cat2" id="store_class_cat2">
			                          <option value="0">请选择二级级分类</option>
			                           <volist  name='store_class_cat2' id='vo'>
			                            <option <if condition="$vo.cat_id  eq I('store_class_cat2')">selected</if> value="{$vo.cat_id}">{$vo.cat_name}</option>
			                          </volist >
			                      </select>
			                    </div>
	  						</div>
	  						
                   		 	<div class="col-xs-1"><input class="btn btn-info margin" type="submit" value="确定"></div>
                   		 	<div class="col-xs-1">
                   		 	    <a href="javascript:;" style="margin:10px;"  id="daochu" class="btn btn-primary pull-right">导出excel</a>
               		 	    </div>
                   		 	
                  		 </form>
                  		 <!--<button type="button" class="btn btn-primary pull-right" id="daochu"><i class="fa fa-file-excel-o"></i>&nbsp;导出excel</button>-->
                 	</div>
		  		 </div>
	             </div><!-- /.box-header -->
	             <div class="box-body">
	           	 <div class="row">
	            	<div class="col-sm-12">
		              <table id="list-table" class="table table-bordered table-striped dataTable" role="grid" aria-describedby="example1_info">
		                 <thead>
		                   <tr role="row">
			                   
                               <th class="sorting" tabindex="0" aria-controls="example1" >排行</th>
			                   <th class="sorting" tabindex="0" aria-controls="example1" >商品名称</th>
			                   <th class="sorting" tabindex="0" aria-controls="example1" >点击率</th>			      
			                   <th class="sorting" tabindex="0" aria-controls="example1" >销售量</th>
			                   <th class="sorting" tabindex="0" aria-controls="example1" >销售额</th>
		                  	   <th class="sorting" tabindex="0" aria-controls="example1" >均价</th>
		                   </tr>
		                 </thead>
						<tbody>
                         <foreach name="list" item="vo" key="k" >
                          <tr role="row" align="center">
                             <td>{$k+1}</td>
                             <td>{$vo.goods_name}</td>
		                     <td style="color: #00c0ef;">{$vo.dianji}</td>
		                     <td style="color: #f39c12;">{$vo.sale_num}</td>		                    
		                     <td style="color: red;">{$vo.sale_amount}</td>
		                     <td>{$vo['sale_amount']/$vo.sale_num|round=###,2}</td>
		                   </tr>
		                  </foreach>
		                   </tbody>
		                 <tfoot>
		                 </tfoot>
		               </table>
	               </div>
	          </div>
              <div class="row">
              	    <div class="col-sm-6 text-left"></div>
                    <div class="col-sm-6 text-right">{$page}</div>		
              </div>
	          </div>
	        </div>
       	</div>
       </div>
   </section>
</div>
<script type="text/javascript">
$(document).ready(function() {
	$('#start_time').daterangepicker({
		format:"YYYY-MM-DD HH:mm",
		singleDatePicker: false,
		showDropdowns: true,
		minDate:'2021-01-01 00:00',
		maxDate:'2030-01-01 00:00',
		startDate:'{:date("Y-m-d")} 00:00',
	    showWeekNumbers: true,
	    timePicker: true,
	    timePickerIncrement: 1,
	    timePicker12Hour: false,
	    ranges: {
	       '今天': [moment(), moment()],
	       '昨天': [moment().subtract('days', 1), moment().subtract('days', 1)],
	       '最近7天': [moment().subtract('days', 6), moment()],
	       '最近30天': [moment().subtract('days', 29), moment()],
	       '上一个月': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
	    },
	    opens: 'right',
	    buttonClasses: ['btn btn-default'],
	    applyClass: 'btn-small btn-primary',
	    cancelClass: 'btn-small',
	    locale : {
	        applyLabel : '确定',
	        cancelLabel : '取消',
	        fromLabel : '起始时间',
	        toLabel : '结束时间',
	        customRangeLabel : '自定义',
	        daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
	        monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
	        firstDay : 1
	    }
	});
	
});

function get_category2(id,next,select_id,lever){
    if(lever == 1){
        $('#cat_id2').html("<option value='0'>请选择商品子分类</option>")
    }
  
    var url = '/index.php?m=Seller&c=Report&a=get_category&parent_id='+ id;
    $.ajax({
        type : "GET",
        url  : url,
        error: function(request) {
            alert("服务器繁忙, 请联系管理员!");
            return;
        },
        success: function(v) {
			v = "<option value='0'>请选择商品子分类</option>" + v;
            $('#'+next).empty().html(v);
			(select_id > 0) && $('#'+next).val(select_id);//默认选中
        }
    });
}

	$("#daochu").click(function(){
	
		var add_time=$("#start_time").val();
		var goods_name=$("#goods_name").val();
		var store_class_cat1=$("#store_class_cat1").val();
		var store_class_cat2=$("#store_class_cat2").val();
		location.href="/index.php/Seller/Report/export_saleTop?goods_name="+goods_name+"&timegap="+add_time+'&goods_name='+goods_name+'&store_class_cat1='+store_class_cat1+'&store_class_cat2='+store_class_cat2;
	})
</script>
</body>
</html>